<template>
  <div class="header-container" ref="headerCon">
    <div class="return" @click="handleLeftEvent">
      <span class="return-icon">
        <em class="iconfont icon-fanhui" />
      </span>
      <span class="return-text" v-if="isReturnText">{{ returnText }}</span>
    </div>
    <h1 class="title">{{ title }}</h1>
    <div class="hd-right">
      <div class="close" v-if="isClose" @click="handleCloseEvent">
        <em class="iconfont icon-guanbi" />
      </div>
      <div
        class="customer-service"
        v-if="isService"
        @click="handleServiceEvent"
      ></div>
    </div>
  </div>
</template>

<script>
import { manualConsultationUrl } from "@/utils";

//页面名称
const GO_BACK_NAME = [
  "BusinessRole",
  "EnterpriseInfoQuery",
  "TelecomLicenseDetails",
  "CredentialDetails",
];

export default {
  name: "HeaderIndex",
  props: {
    isReturnText: {
      //是否需要返回文字
      type: Boolean,
      default: true,
    },
    returnText: {
      //返回文字
      type: String,
      default: "返回",
    },
    title: {
      //标题
      type: String,
      default: "法务智能机器人为您服务",
    },
    isClose: {
      //是否显示关闭按钮
      type: Boolean,
      default: true,
    },
    isService: {
      //是否显示客服按钮
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    //阻止顶部栏默认事件
    this.$refs.headerCon.addEventListener(
      "touchmove",
      function (e) {
        e.preventDefault();
      },
      { passive: false }
    );
  },
  methods: {
    /**
     * 左侧事件
     */
    handleLeftEvent() {
      //返回的上一页是否为GO_BACK_NAME数组中的页面
      sessionStorage.setItem(
        "isGoBack",
        GO_BACK_NAME.includes(this.$route.name)
      );

      // 首页点击返回按钮关闭应用，反之返回上一页
      this.$route.name == "Home" ? MXWebui.closeWindow() : this.$router.go(-1);
    },

    /**
     * 关闭应用
     */
    handleCloseEvent() {
      MXWebui.closeWindow();
    },

    /**
     * 打开人工咨询页面
     */
    handleServiceEvent() {
      MXCommon.openUrlPage(manualConsultationUrl());
    },
  },
};
</script>

<style lang="less" scoped>
@import url("~@/assets/styles/header/index.less");
</style>